<template>
  <div class="my-page">
    <div class="header">
      <img class="img1" src="http://liufusong.top:8080/img/profile/bg.png" alt="背景图">
      <div class="first">
           <img class="img2" :src="avatar" alt="头像">
           <p>{{ nickname }}</p>
           <div class="button">
             <p @click="$router.push('/login')"  v-if="isLogin">去登录</p>
             <p @click="Tologin" v-else>退出</p>
           </div>
           <!-- <div class="botton" @click="$router.push('/login')" v-if="isLogin">去登录</div>
           <div class="botton" @click="Tologin" v-else>退出</div> -->
      </div>
     <!-- <div class="second" v-else>
           <img  class="img2"  alt="">
           <p>{{nickname}}</p>

     </div> -->
    </div>
    <div class="main">
      <van-grid :column-num="3">
  <van-grid-item  @click="toCollect" icon="star-o" text="我的收藏" />
  <van-grid-item  @click="toLease"   icon="wap-home-o" text="我的出租" />
  <van-grid-item icon="underway-o" text="看房记录" />
  <van-grid-item icon="credit-pay" text="成为房主" />
  <van-grid-item icon="contact" text="个人资料" />
  <van-grid-item icon="service-o" text="联系我们" />
</van-grid>
    </div>

<div class="pic">
  <img src="http://liufusong.top:8080/img/profile/join.png" alt="">
</div>
  </div>
</template>

<script>
import { getuserInfo, logout } from '@/api/user'
import { delToken, getToken } from '@/utils/storage'
export default {
  name: 'HkzfVantMy',

  data () {
    return {
      isLogin: true,
      nickname: '游客',
      avatar: 'http://liufusong.top:8080/img/profile/avatar.png',
      user: {}
    }
  },

  async created () {
    const res = await getuserInfo()
    console.log(res)
    const token = getToken()
    if (token && res.status !== 400) {
      this.user = res.body
      this.nickname = res.body.nickname
      this.avatar = 'http://liufusong.top:8080' + res.body.avatar
      if (res.status === 200) {
        this.isLogin = false
      }
    }
  },

  methods: {

    async  Tologin () {
      await logout()
      // console.log(res)

      delToken()
      this.$toast.success('退出成功！')
      // this.$router.push('/login')
      this.isLogin = true
    },
    toCollect () {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      this.$router.push('/collect')
    },
    toLease () {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      this.$router.push('/lease')
    }
  }
}
</script>

<style lang="less" scoped>
.my-page {
  position: relative;
  min-height: 300px
}
.my-page .img1{
   width: 100%
 }
.my-page .first {
  position: absolute;
  background-color: #fff;
  width: 312px;
  height: 170px;
  left: 8%;
  top: 140px;
  box-shadow: 0 0 10px 3px #ddd;
  text-align: center;
  font-weight: 400;
  font-size: 13px
}
.my-page .img2 {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-top: -30px;
}
p {
 padding-top: 2px;
}
.my-page .button p{
   width: 50px;
   height: 30px;
   font-size: 13px;
   line-height: 30px;
    padding: 0 15px;
    margin: 0 auto;
    margin-top: 18px;
    border-radius: 15px;
    color: #fff;
    background-color: #21b97a;
}
.my-page .main {
  margin-top: 140px;
}
.my-page .pic {
  margin-top: 40px;
  margin: 0 auto;
  width: 90%;
  height: 80px;
}
.my-page .pic img {
  width: 100%;
  height: 100%;
}
</style>
